import { FC, useEffect } from '_@types_react@17.0.62@@types/react';
import React, { useState } from 'react';
import { message, Table } from 'antd';
import { Link, useHistory } from 'umi';
import type { ColumnsType } from 'antd/es/table';
import {
  getActivityStatus,
} from '@/services/activityInfo';
  // 元素类型定义
  interface DataType {
    key: string;
    activityLabel: string;
    organizationalUnit: string;
    activityAddress: string;
    startTime: string;
    endTime:string;
  }
  interface ActivityTableProps {
    activeList: any; // 将具体的数据类型替换any，根据实际数据结构定义
  }
const ActivityTable: FC<ActivityTableProps> = ({ activeList }) => {
  // 列定义
  const columns: ColumnsType<DataType> = [
    {
      title: '活动名称',
      dataIndex: 'activityLabel',
      key: 'activityLabel',
      width: '20%',
      render: (text, record: any)=>{
        return <a onClick={()=>{
          // 如果不是教师
          if (localStorage.getItem("roleId") != '2'){
            // 如果是父活动直接跳转
            if (record.parentsId === null){
              window.location.replace("/activityInfo/activityDetails?activityId="+record.id)
            }else {
              let data = {
                stuNumber: localStorage.getItem('userAccount'),
                activityId: record.parentsId,
              }
              getActivityStatus(data).then((response: any) => {
                if (response.result === 2){
                  window.location.replace("/activityInfo/activityDetails?activityId="+record.id)
                }else {
                  message.warn("请先通过父类活动的报名审核！")
                }
              })
            }
          }else {
            window.location.replace("/activityInfoTeacher/activityDetails?activityId="+record.id)
          }
        }
        }>{text}</a>

      }
    },
    {
      title: '举办方',
      dataIndex: 'organizationalUnit',
      key: 'organizationalUnit',
      width: '20%',
    },
    {
      title: '举办地点',
      dataIndex: 'activityAddress',
      key: 'activityAddress',
      width: '20%',
    },
    {
      title: '开始时间',
      dataIndex: 'startTime',
      key: 'startTime',
      width: '20%',
      render: (startTime: string) => {
        const date = new Date(startTime);
        return date.toLocaleString(); // 使用toLocaleString()方法将时间格式化为本地日期时间字符串
      },
    },
    {
      title: '结束时间',
      dataIndex: 'endTime',
      key: 'endTime',
      width: '20%',
      render: (endTime: string) => {
        const date = new Date(endTime);
        return date.toLocaleString(); // 使用toLocaleString()方法将时间格式化为本地日期时间字符串
      },
    },
  ];

  return(
      <Table
        columns={columns}
        rowKey="id"
        dataSource={activeList}
      />

  )
}

export default ActivityTable;
